package com.ssy.common.utils;

import com.ssy.common.CodeMsg;
import com.ssy.common.Constant;
import lombok.Data;

import java.io.Serializable;

/**
 * @author ssy
 * <p>
 * 返回前段数据封装
 */
@Data
public class Result implements Serializable {

    private static final long serialVersionUID = 2745253092884646060L;

    //状态码
    private Integer code;
    //业务消息
    private String msg = Constant.MESSAGE;
    //封装的数据
    private Object data;

    /**
     * 默认没有数据的 成功的Result
     */
    public Result() {
        this.code = CodeMsg.SUCCESS.CODE;
        this.msg = CodeMsg.SUCCESS.MSG;
    }

    /**
     * 业务正确的Result
     *
     * @param data
     */
    public Result(Object data) {
        this.code = CodeMsg.SUCCESS.CODE;
        this.msg = CodeMsg.SUCCESS.MSG;
        this.data = data;
    }

    public Result(CodeMsg codeMsg) {
        this.code = codeMsg.CODE;
        this.msg = codeMsg.MSG;
    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(Object data, String msg) {
        this.code = CodeMsg.SUCCESS.CODE;
        this.msg = msg;
        this.data = data;
    }

}
